package jzqb.controller;

import haha.life.common.CutPageBean;
import io.swagger.annotations.ApiOperation;
import jzqb.bo.DynamicNewsBo;
import jzqb.common.Result;
import jzqb.service.IDynamicNewsService;
import jzqb.vo.DynamicNewsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description:动态新闻
 *
 * @author BaiGe
 * @date: 2021/4/27 9:54
 * @Version 1.0
 */
@RestController
@RequestMapping("/dynamicNews")
public class DynamicNewsController {
    @Autowired
    private IDynamicNewsService dynamicNewsService;

    @ApiOperation(value = "首页展示5条动态科技")
    @PostMapping("/showDynamicNewsOfIndexPage")
    public Result showDynamicNewsOfIndexPage() {
     List<DynamicNewsVo> DynamicNewsList = dynamicNewsService.showDynamicNewsLimitFive();
        return Result.succ(DynamicNewsList);
    }


    @ApiOperation(value = "展示动态科技-前台")
    @PostMapping("/queryDynamicNewsOfFront")
    public Result queryDynamicNewsOfFront(@RequestBody DynamicNewsBo dynamicNewsBo) {
        dynamicNewsBo.setPage(dynamicNewsBo.getPage());
        dynamicNewsBo.setPageSize(dynamicNewsBo.getPageSize());
        dynamicNewsBo.setStart(dynamicNewsBo.getPage(),dynamicNewsBo.getPageSize());
        CutPageBean<DynamicNewsVo> cutPageBean = dynamicNewsService.queryDynamicNewsOfFront(dynamicNewsBo);
        return Result.succ(cutPageBean);
    }

    @ApiOperation(value = "科技动态详情页 -前台")
    @PostMapping("/dynamicNewsInfo")
    public Result dynamicNewsInfo(@RequestBody DynamicNewsBo dynamicNewsBo) {
        DynamicNewsVo dynamicNews = dynamicNewsService.getDynamicNewsById(dynamicNewsBo.getId());
        return Result.succ(dynamicNews);
    }

}
